<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/10/22
 * Time: 16:05
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\common\model\mysql;

use app\common\lib\Status;

class MoneyList extends Base
{
    /**
     * 查询所有提现金额 且不查询提现失败的
     * @param string $openid
     * @return Money|array|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getMoneyListByCount(string $openid = '')
    {
        return $this->field("id,sum(money) as money")
            ->where('openid', $openid)
            ->where('state', '<>', 2)
            ->find();
    }

    /**
     * @param array $where
     * @param int $limit
     * @param int $page
     * @return array
     * @throws \think\db\exception\DbException
     */
    public function getMoneyListByList(array $where = [], int $limit = 10, int $page = 1)
    {
        return $this
            ->where($where)
            ->order('id desc')
            ->paginate([
                'list_rows' => $limit,
                'var_page' => 'page',
                "page" => $page
            ])
            ->toArray();
    }
}